<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\agent\service;

class AdminUserService
{
    public static function addAdminUser($uniacid, $input)
    {
        $subAdmin = \app\agent\model\AdminModel::where([["account", "=", $input["account"]], ["status", "=", 1]])->findOrEmpty();
        if(!$subAdmin->isEmpty()) {
            return false;
        }
        $offset = createOffset();
        $new = ["admin_id" => $input["uuid"], "account" => $input["account"], "uniacid" => $uniacid, "offset" => $offset, "passwd" => createPasswd($input["passwd"], $offset), "role_id" => $input["role_id"], "creator_id" => $input["admin_id"], "status" => 1];
        $rst = $subAdmin->save($new);
        if(!$rst) {
            return false;
        }
        return true;
    }
    public static function initDefaultRole()
    {
        $adminRole = new \app\agent\model\AdminRoleModel();
        $data = [];
        if(!$adminRole->where(["role_id" => "e1af223e997011e997cb77d35351cc48"])->count()) {
            $data[] = ["role_id" => "e1af223e997011e997cb77d35351cc48", "role_name" => "admin", "description" => "超级管理员", "create_time" => NULL, "update_time" => NULL, "delete_time" => NULL, "deleted" => "0", "uniacid" => "8888"];
        }
        if(!$adminRole->where(["role_id" => "e7d81116997011e99b985595a87cbdcb"])->count()) {
            $data[] = ["role_id" => "e7d81116997011e99b985595a87cbdcb", "role_name" => "user", "description" => "普通用户", "create_time" => NULL, "update_time" => NULL, "delete_time" => NULL, "deleted" => "0", "uniacid" => "8888"];
        }
        $adminRole->saveAll($data);
    }
    public static function bindAppAdmin($data)
    {
        if(\app\agent\model\AppAdminModel::where(["id" => $data["id"]])->count()) {
            return false;
        }
        $appAdmin = new \app\agent\model\AppAdminModel();
        $appAdmin->save($data);
    }
    public static function getSassNum($key, $uniacid)
    {
        $className = "Permission" . ucfirst($key);
        $permissionPath = APP_PATH . $key . "/info/" . $className . ".php";
        $num = 0;
        if(file_exists($permissionPath) && (require_once $permissionPath)) {
            $permissionClassName = "app\\" . $key . "\\info\\" . $className;
            $permission = new $permissionClassName($uniacid);
            $num = $permission->getAuthNumber();
        }
        return $num;
    }
}

?>